package com.itcast.donkey.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.itcast.donkey.R;
import com.itcast.donkey.modles.TravelInHeadLikeModels;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/9/19.
 */
public class InHeadLikeAdapter extends RecyclerView.Adapter<InHeadLikeAdapter.MyHolder> {
    private Context context;
    private List<TravelInHeadLikeModels> models = new ArrayList<>();

    public InHeadLikeAdapter(Context context, List<TravelInHeadLikeModels> models) {
        this.context = context;
        this.models = models;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_in_head_like, null);
        MyHolder holder = new MyHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        if (models.size() > 0) {
            holder.likePhoto.setVisibility(View.VISIBLE);
            Picasso.with(context).load(models.get(position).getPhoto_url()).into(holder.likePhoto);
            holder.linLike.setVisibility(View.GONE);
        } else {
            holder.linLike.setVisibility(View.VISIBLE);
            holder.likePhoto.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return models.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        private ImageView likePhoto;
        private LinearLayout linLike;

        public MyHolder(View itemView) {
            super(itemView);
            likePhoto = (ImageView) itemView.findViewById(R.id.like_photo);
            linLike = (LinearLayout) itemView.findViewById(R.id.lin_like);
        }
    }
}
